﻿# -*- coding: utf-8 -*-

import os

# 定义文件夹路径
folder_path = 'D:\\static_webPage\\'
# txt 文件名
txt_name_list = []
if __name__ == "__main__":
    f = os.walk(folder_path)
    # 获取静态网址名称
    for dirpath, dirnames, filenames in f:
        if ('_files' in dirpath):
            txt_name = dirpath.split('_files')[0].split('\\')[-1] + '_files';
            if txt_name not in txt_name_list:
                txt_name_list.append(txt_name)

    print(txt_name_list)
        # print(dirnames)
        # print(filenames)
    for file_name in txt_name_list:
        # 获取该路径下的静态页面
        f = os.walk(folder_path + file_name)

        # 获取静态网址名称
        for dirpath, dirnames, filenames in f:
            print(filenames)
            for file in filenames:
                # 判断文件后缀是否满足要求
                if file.endswith('.html'):
                    # 打开输出文件，准备写入
                    with open(folder_path + file_name + '.txt', 'a', encoding='utf-8') as f:
                        # 写入文件名到txt文件中，每个文件名后添加一个换行符
                        f.write(file + '\n')





